import { View, Text, TouchableOpacity } from 'react-native';
import React from 'react';
import PropTypes from 'prop-types';
import { Modal } from '@ant-design/react-native';
import moment from 'moment';
import styles from './styles';
import { debounce } from '../../../../utils/common';
import { moveToLogBin } from '../../../../comconfig/sqlfun';

const Item = ({ navigation, getList, objItem }) => (
    <TouchableOpacity
        style={styles.itembg}
        onPress={
            () => debounce(() => navigation.push('添加日志',
                { id: objItem.id, isEditing: true }), 200)
        }
        onLongPress={() => Modal.operation([
            {
                text: '删除',
                onPress: () => {
                    moveToLogBin(parseInt(objItem.id, 10), `${objItem.workname}的工作日志`);
                    getList();
                },
                style: { color: '#0F8DE9' },
            },
        ])}
    >
        <View>
            <Text
                style={styles.title}
                numberOfLines={1}
                ellipsizeMode="middle"
            >
                {`${objItem.workname}的工作日志`}
            </Text>
            <Text
                style={styles.title}
                numberOfLines={1}
                ellipsizeMode="middle"
            >
                {objItem.work}
            </Text>
            <View
                style={styles.time}
            >
                <Text>{moment(objItem.time).format('YYYY-MM-DD')}</Text>
            </View>
        </View>
    </TouchableOpacity>
);

Item.defaultProps = {
    objItem: {},
    getList: () => {},
};
Item.propTypes = {
    objItem: PropTypes.objectOf(PropTypes.any),
    getList: PropTypes.func,
};
export default Item;
